import {defineStore} from 'pinia'
import request from '@/utils/request'
import {ResApi,BannerItem,GoodsItem,HotGoods,Brand} from '@/types/data'

const useHomeStore = defineStore('home',{
    state(){
        return {
            // 轮播图片信息
            bannerList:[] as BannerItem[],
            // 新鲜好物数据信息
            newGoodsList:[] as GoodsItem[],
            // 人气推荐数据信息
            hotGoodsList:[] as HotGoods[],
            // 热门品牌数据信息
            brandList:[] as Brand[]
        }
    },
    actions:{
        async getHomeBanner(){
           const res = await request.get<ResApi<BannerItem[]>>('/home/banner')
           this.bannerList = res.data.result
        },

        async getNewGoodsList(){
            // const res = await request.get<ResApi<GoodsItem[]>>('/home/new')
            // this.newGoodsList = res.data.result

            setTimeout(async ()=>{
                const res = await request.get<ResApi<GoodsItem[]>>('/home/new')
                this.newGoodsList = res.data.result
            },2000)
        },

        async getHotGoodsList(){
            // const res = await request.get<ResApi<HotGoods[]>>('/home/hot')
            // this.hotGoodsList = res.data.result

            setTimeout(async ()=>{
                const res = await request.get<ResApi<HotGoods[]>>('/home/hot')
            this.hotGoodsList = res.data.result
            },2000)

        },

        async getBrandList() {
            const res = await request.get<ResApi<Brand[]>>('/home/brand')
            console.log(res)
            this.brandList = res.data.result
        },
    },
    getters:{}
})

export default useHomeStore